import os.path
import time
import HTMLTestRunner
import unittest

# 测试报告路径
report_path = os.path.abspath('report')

# 测试报告文件名
html_report_filename = time.strftime('%Y-%m-%d %H-%M-%S') + '-HTMLReport.html'

# 完整路径
html_report_path = os.path.join(report_path, html_report_filename)

# 加载测试用例(测试套件)
loader = unittest.defaultTestLoader.discover('test_cases', pattern='test*')

# 读取报告,写入内容
with open(html_report_path, 'wb') as f:
    runner = HTMLTestRunner.HTMLTestRunner(
        title='自动化测试报告',
        description='自动化测试报告描述',
        stream=f,
        verbosity=2
    )
    # 执行
    runner.run(loader)
